#!/sbin/runscript
# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

PROGRAM="xproofd"

CONF_NAME="/etc/conf.d/${PROGRAM}"

PID_FILE="/var/run/${PROGRAM}.pid"

depend() {
        need net
}

checkconfig() {
        if [ ! -e ${CONF_NAME} ] ; then
                eerror "Please setup ${CONF_NAME} before starting ${PROGRAM}"
                return 1
        fi

}

start() {
        checkconfig || return 1
        ebegin "Starting ${PROGRAM}"

	if [ -z "$ALICE_PROOF_AAF_DIR" ];then
	  echo "\$ALICE_PROOF_AAF_DIR is not defined !!! Make sure that you sourced aaf.cf file !!!"
	  return 2
	fi
        start-stop-daemon --start --exec $XPRFROOTSYS/bin/$PROGRAM \
                --background --make-pidfile --pidfile "${PID_FILE}" \
                -- -l $XPRFLOG -R $XPRFUSER -c $XPRFCF $XPRFDEBUG
        sleep 1
	kill -0 `cat ${PID_FILE}` &> /dev/null
	RET=$?
	if [ $RET != "0" ];then
	    rm -f "${PID_FILE}"
	fi
        eend $RET
}

stop() {
        ebegin "Stopping ${PROGRAM}"
	if [ -z "$ALICE_PROOF_AAF_DIR" ];then
	  echo "\$ALICE_PROOF_AAF_DIR is not defined !!! Make sure that you sourced aaf.cf file !!!"
	  return 2
	fi
        start-stop-daemon --stop --exec $XPRFROOTSYS/bin/${PROGRAM} \
        --pidfile "${PID_FILE}"
        eend $?
}
